var t = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (t) {
  return typeof t
}
  : function (t) {
    return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t
  },
  e = require("check");
module.exports = {
  toQueryPair: function (t, e) {
    return void 0 === e ? t : t + "=" + encodeURIComponent(null === e ? "" : String(e))
  },
  /*
  *处理请求路径
  * @param n 方法名
  * @param o 参数
  * return  string
  */
  getUrl: function (n, o, i) {
    n = n.replace(/\//gi, "/");
    var a = getApp().globalData.api + "api/" + n;
    return o && ("object" == (void 0 === o ? "undefined" : t(o)) ? a += "?app_id=" + getApp().globalData.appid+"&" + e.param(o) : "string" == typeof o && (a += "&" + o)),
      a
  },
  /*
     *处理请求路径格式
     * @param t:缓存值
     * @param n:data参数
     * @param o:success后返回值
     * @param a:请求类型
     * return  string
     */
  json: function (t, n, o, i, a, c) {//t:缓存值，n:data参数，o:success后返回值，i:  a:请求类型
    var r = getApp();
    var d = r.requirejs("core");
    i && d.loading()
    var p = a ? this.getUrl(t) : this.getUrl(t, n),
      l = {
        url: p,
        method: a ? "POST" : "GET",
        header: {
          "Content-type": a ? "application/x-www-form-urlencoded" : "application/json",
        }
      };
    a && (l.data = e.param(n)),//参数
      o && (l.success = function (t) {
        i && d.hideLoading(),
          "request:ok" == t.errMsg && "function" == typeof o, o(t.data)
      }),
      wx.request(l)
    console.log(l)
  },
  /*
  *post请求
  * @param n 方法名
  * return  string
  */
  post: function (t, e, n, o, i) {
    this.json(t, e, n, o, true, i)
  },
  /*
  *get请求
  * @param n 方法名
  * return  string
  */
  get: function (t, e, n, o, i) {
    this.json(t, e, n, o, false, i)
  },

  alert: function (e, n) {
    "object" === (void 0 === e ? "undefined" : t(e)) && (e = JSON.stringify(e)),
      wx.showModal({
        title: "提示",
        content: e,
        showCancel: false,
        success: function (t) {
          t.confirm && "function" == typeof confirm && n()
        }
      })
  },
  confirm: function (e, n, o) {
    "object" === (void 0 === e ? "undefined" : t(e)) && (e = JSON.stringify(e)),
      wx.showModal({
        title: "提示",
        content: e,
        showCancel: true,
        success: function (t) {
          t.confirm ? "function" == typeof n && n() : "function" == typeof o && o()
        }
      })
  },
  loading: function (t) {
    void 0 !== t && "" != t || (t = "加载中"),
      wx.showToast({
        title: t,
        icon: "loading",
        duration: 5e6
      })
  },
  hideLoading: function () {
    wx.hideToast()
  },
  toast: function (t, e) {
    e || (e = "success"),
      wx.showToast({
        title: t,
        icon: e,
        duration: 1000
      })
  },
  success: function (t) {
    wx.showToast({
      title: t,
      icon: "success",
      duration: 1000
    })
  },
  upload: function (t) {
    var e = this;
    wx.chooseImage({
      success: function (n) {
        e.loading("正在上传...");
        var o = e.getUrl("util/uploader/upload", {
          file: "file"
        }),
          i = n.tempFilePaths;
        wx.uploadFile({
          url: o,
          filePath: i[0],
          name: "file",
          success: function (n) {
            e.hideLoading();
            var o = JSON.parse(n.data);
            if (0 != o.error)
              e.alert("上传失败");
            else if ("function" == typeof t) {
              var i = o.files[0];
              t(i)
            }
          }
        })
      }
    })
  },
  pdata: function (t) {
    return t.currentTarget.dataset
  },
  data: function (t) {
    return t.target.dataset
  },
  phone: function (t) {
    var e = this.pdata(t).phone;
    wx.makePhoneCall({
      phoneNumber: e
    })
  },
  onShareAppMessage: function (url, t) {
    var title = t || "壹佰商城";
    var path = url || "/pages/index/index";
    return {
      title: title,
      path: path
    }
  }
}